package com._21cn.cms.article.service;

import com._21cn.cms.article.Constants;
import com._21cn.framework.base.db.BaseDao;
import com._21cn.framework.base.service.impl.BaseServiceImpl;

import com._21cn.cms.article.dao.ColumnArticleDao;
import com._21cn.cms.article.entity.ColumnArticle;

import com._21cn.framework.flip.PageHashMap;
import com._21cn.framework.flip.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("columnArticleService")
public class ColumnArticleService extends BaseServiceImpl<ColumnArticle> {
	
    @Autowired
    private ColumnArticleDao columnArticleDao;

    @Override
    protected BaseDao<ColumnArticle> getBaseDao() {
        return columnArticleDao;
    }

    //获取栏目文章
    public ColumnArticle getColumnArticle( int columnId, int articleId ){
        Map<String,Object> paramMap = new HashMap<String,Object>();
        paramMap.put("eqColumnId", columnId);
        paramMap.put("eqArticleId", articleId);
        PageList<ColumnArticle> list = getList(paramMap, 1, 1, false);
        return list.isEmpty() ? null : list.get(0);
    }

    //获取主栏目文章
    public ColumnArticle getMasterArticle( int articleId ){
        Map<String,Object> paramMap = new HashMap<String,Object>();
        paramMap.put("eqSlaveFlag", Constants.PUBLISH_COLUMN_MASTER);
        paramMap.put("eqArticleId", articleId);
        PageList<ColumnArticle> list = getList(paramMap, 1, 1, false);
        return list.isEmpty() ? null : list.get(0);
    }

    public PageList<ColumnArticle> getListByIds(List<Integer> idList) {
        PageList result = new PageList();
        if (!idList.isEmpty()) {
            Map params = new HashMap();
            params.put("inArticleIdList", idList);
            result = getList(params, 1, idList.size()*5, false);    // FIXME: 2019/3/2
        }
        return result;
    }
}